package com.yyq.sos.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.yyq.adms.sysmanage.pojo.DataDictionary;
import com.yyq.adms.usermanage.dao.impl.SysDeptsDaoImpl;
import com.yyq.adms.usermanage.pojo.SysDepts;
import com.yyq.servlets.ApplicationContextHandle;

/**
 * 系统参数实用类
 * @author Administrator
 */
public class DepartmentUtil 
{
	
	private static Map map = new HashMap();
	private final static DepartmentUtil instance = new DepartmentUtil();

	private DepartmentUtil()
	{
		
		SysDeptsDaoImpl dao = (SysDeptsDaoImpl)ApplicationContextHandle.getBean("sysDeptsDao");
		String hql = "from SysDepts where deptType=1 and parentId=0";
		List list = dao.search(hql);
		for(int i=0; i<list.size(); ++i){
			SysDepts obj = (SysDepts)list.get(i);
			map.put(obj.getDeptCname(),obj.getId());
		}
	}
	
	public static DepartmentUtil getInstance()
	{
		return instance;
	}
	
	public Long getValue(String param)
	{
		return (Long)map.get(param);
	}
	
	public void add(String param,Long value){
		map.put(param, value);
	}
	
	public void delete(String param)
	{
		map.remove(param);
	}
	
	public List<DataDictionary> getSentDeps(){
		List<DataDictionary> dds = new ArrayList<DataDictionary>();
		Set set = map.keySet();
		for (Object obj : set) {
			DataDictionary dd = new DataDictionary();
			dd.setText(obj.toString());
			dd.setValue(obj.toString());
			dds.add(dd);
		}
		return dds;
	}
}
